const traceabilityQuery = [
  {
    id: 1,
    name: '炖煮牛肉块',
    material: {
      supplierName: '新鲜农庄',
      principal: '李先生',
      place: '本地农田',
      quantity: '1000',
      price: '10000',
      date: '2020-05-26T09:42:56Z',
    },
    materialWareHouse: {
      principal: '张三',
      warehouse: '仓库A',
      weight: '100',
      quality: '良好',
      date: '2022-01-01',
    },
    cleanCutting: {
      principal: '张三',
      place: '车间A',
      weight: '100',
      quality: '合格',
      date: '2022-01-01',
    },
    boilingCooling: {
      principal: '张三',
      place: '车间A',
      weight: '100',
      quality: '合格',
      date: '2022-01-01',
    },
    qualityTest: {
      batch: '20220101',
      principal: '张三',
      place: 'A车间',
      quantity: '合格',
      date: '2022-01-01',
      reason: '无',
    },
  },
  {
    id: 2,
    name: '蒸熟胡萝卜',
    material: {
      supplierName: '新鲜农庄',
      principal: '李先生',
      place: '本地农田',
      quantity: '1000',
      price: '10000',
      date: '2020-05-26T09:42:56Z',
    },
    materialWareHouse: {
      principal: '张三',
      warehouse: '仓库A',
      weight: '100',
      quality: '良好',
      date: '2022-01-01',
    },
    cleanCutting: {
      principal: '张三',
      place: '车间A',
      weight: '100',
      quality: '合格',
      date: '2022-01-01',
    },
    boilingCooling: {
      principal: '张三',
      place: '车间A',
      weight: '100',
      quality: '合格',
      date: '2022-01-01',
    },
    qualityTest: {
      batch: '20220101',
      principal: '张三',
      place: 'A车间',
      quantity: '合格',
      date: '2022-01-01',
      reason: '无',
    },
  },
];

export default {
  'POST /api/traceabilityQuery': (req: any, res: any) => {
    const { id } = req.body; // 获取请求中的id参数

    const item = traceabilityQuery.find((item) => item.id === Number(id)); // 在数据数组中查找对应ID的项

    if (item) {
      res.json({
        success: true,
        data: [item], // 返回找到的数据项
        errorCode: 0,
      });
    } else {
      res.json({
        success: false,
        message: '未找到对应ID的数据',
        errorCode: 404,
      });
    }
  },
};
